using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication4
{
    public partial class ReportDisplay : UserControl
    {
        /// <summary>
        /// can be null
        /// </summary>
        VillageIntel villageIntel;

        public ReportDisplay()
        {
            InitializeComponent();
        }

        public VillageIntel ReportToDisplay
        {
            set
            {
                this.villageIntel = value;
                DisplayIntel();
            }
        }

        private void DisplayIntel()
        {
            if (villageIntel != null)
            {
                lblReportFrom.Text = "Report from " + villageIntel.ReportFrom;
                lblDaysOld.Text = "[" + villageIntel.ReportAgeInDays.ToString("0.#") + " days old]";
                if (villageIntel.ReportAgeInDays < 2)
                {
                    lblDaysOld.ForeColor = Color.Green;
                    lblReportFrom.ForeColor = Color.Green;
                }
                else if (villageIntel.ReportAgeInDays > 5)
                {
                    lblDaysOld.ForeColor = Color.Crimson;
                    lblReportFrom.ForeColor = Color.Crimson;
                }
                else
                {
                    lblDaysOld.ForeColor = Color.DarkGoldenrod;
                    lblReportFrom.ForeColor = Color.DarkGoldenrod;
                }
                System.Diagnostics.Trace.WriteLine(lblReportFrom.Text + DateTime.Now.Ticks.ToString());

                int Iindex = (int)World.CONSTS.ReportsTable.Columns.in_troop_startIndex;
                lblISP.Text = TroopCountAsString(villageIntel.drIntel[Iindex]);
                lblISW.Text = TroopCountAsString(villageIntel.drIntel[Iindex + 1]);
                lblIAxe.Text = TroopCountAsString(villageIntel.drIntel[Iindex + 2]);
                lblIscout.Text = TroopCountAsString(villageIntel.drIntel[Iindex + 3]);
                lblILC.Text = TroopCountAsString(villageIntel.drIntel[Iindex + 4]);
                lblIHC.Text = TroopCountAsString(villageIntel.drIntel[Iindex + 5]);
                lblIRam.Text = TroopCountAsString(villageIntel.drIntel[Iindex + 6]);
                lblICAT.Text = TroopCountAsString(villageIntel.drIntel[Iindex + 7]);
                lblINoble.Text = TroopCountAsString(villageIntel.drIntel[Iindex + 8]);

                int Oindex = (int)World.CONSTS.ReportsTable.Columns.out_troop_startIndex;
                lblOSP.Text = TroopCountAsString(villageIntel.drIntel[Oindex]);
                lblOSW.Text = TroopCountAsString(villageIntel.drIntel[Oindex + 1]);
                lblOAxe.Text = TroopCountAsString(villageIntel.drIntel[Oindex + 2]);
                lblOscout.Text = TroopCountAsString(villageIntel.drIntel[Oindex + 3]);
                lblOLC.Text = TroopCountAsString(villageIntel.drIntel[Oindex + 4]);
                lblOHC.Text = TroopCountAsString(villageIntel.drIntel[Oindex + 5]);
                lblORam.Text = TroopCountAsString(villageIntel.drIntel[Oindex + 6]);
                lblOCAT.Text = TroopCountAsString(villageIntel.drIntel[Oindex + 7]);
                lblONoble.Text = TroopCountAsString(villageIntel.drIntel[Oindex + 8]);


                lblTSP.Text = TroopCountAsString((int)villageIntel.drIntel[Iindex] + ((int)villageIntel.drIntel[Oindex] == -1 ? 0 : (int)villageIntel.drIntel[Oindex]) );
                lblTSW.Text = TroopCountAsString((int)villageIntel.drIntel[Iindex + 1] + ((int)villageIntel.drIntel[Oindex] == -1 ? 0 : (int)villageIntel.drIntel[Oindex + 1]));
                lblTAxe.Text = TroopCountAsString((int)villageIntel.drIntel[Iindex + 2] + ((int)villageIntel.drIntel[Oindex] == -1 ? 0 : (int)villageIntel.drIntel[Oindex + 2]));
                lblTscout.Text = TroopCountAsString((int)villageIntel.drIntel[Iindex + 3] + ((int)villageIntel.drIntel[Oindex] == -1 ? 0 : (int)villageIntel.drIntel[Oindex + 3]));
                lblTLC.Text = TroopCountAsString((int)villageIntel.drIntel[Iindex + 4] + ((int)villageIntel.drIntel[Oindex] == -1 ? 0 : (int)villageIntel.drIntel[Oindex + 4]));
                lblTHC.Text = TroopCountAsString((int)villageIntel.drIntel[Iindex + 5] + ((int)villageIntel.drIntel[Oindex] == -1 ? 0 : (int)villageIntel.drIntel[Oindex + 5]));
                lblTRam.Text = TroopCountAsString((int)villageIntel.drIntel[Iindex + 6] + ((int)villageIntel.drIntel[Oindex] == -1 ? 0 : (int)villageIntel.drIntel[Oindex + 6]));
                lblTCat.Text = TroopCountAsString((int)villageIntel.drIntel[Iindex + 7] + ((int)villageIntel.drIntel[Oindex] == -1 ? 0 : (int)villageIntel.drIntel[Oindex + 7]));
                lblTNoble.Text = TroopCountAsString((int)villageIntel.drIntel[Iindex + 8] + ((int)villageIntel.drIntel[Oindex] == -1 ? 0 : (int)villageIntel.drIntel[Oindex + 8]));
        
                if ((int)villageIntel.drIntel[World.CONSTS.ReportsTable.Columns.WallIndex] == -1)
                {
                    lblWall.Text = "?";
                }
                else
                {
                    lblWall.Text = villageIntel.drIntel[World.CONSTS.ReportsTable.Columns.WallIndex].ToString();
                }
            }
            else
            {

                Clear();
            }
        }

        private string TroopCountAsString(object count)
        {
            int i = (int) count;
            if (i == -1)
            {
                return "?";
            }
            else
            {
                return i.ToString("#,###");
            }
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void lblTSP_Click(object sender, EventArgs e)
        {

        }

        private void label27_Click(object sender, EventArgs e)
        {

        }

        private void label25_Click(object sender, EventArgs e)
        {

        }

        private void label24_Click(object sender, EventArgs e)
        {

        }

        private void Clear() 
        {
            lblReportFrom.Text = "No Report. Right click village to download";

            lblISP.Text = "";
            lblISW.Text = "";
            lblIAxe.Text = "";
            lblIscout.Text = "";
            lblILC.Text = "";
            lblIHC.Text = "";
            lblIRam.Text = "";
            lblICAT.Text = "";
            lblINoble.Text = "";

            lblOSP.Text = "";
            lblOSW.Text = "";
            lblOAxe.Text = "";
            lblOscout.Text = "";
            lblOLC.Text = "";
            lblOHC.Text = "";
            lblORam.Text = "";
            lblOCAT.Text = "";
            lblONoble.Text = "";

            lblTSP.Text = "";
            lblTSW.Text = "";
            lblTAxe.Text = "";
            lblTscout.Text = "";
            lblTLC.Text = "";
            lblTHC.Text = "";
            lblTRam.Text = "";
            lblTCat.Text = "";
            lblTNoble.Text = "";

            lblWall.Text = "";
            lblDaysOld.Text = "";

        }

        private void ReportDisplay_Load(object sender, EventArgs e)
        {
            Clear();

        }
    }
}
